package org.display.graphic.line
{
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import mx.containers.Canvas;
	import mx.flash.UIMovieClip;
	
	import org.display.graphic.*;
	import org.utils.*;

	public class RotLine extends UIMovieClip
	{
		private var line:Sprite
		private var linecolor
		private var linethick
		private var rot:Sprite
		
		public var obj1:Iv
		public var obj2:Iv
		
		public function RotLine(linethick,linecolor,p1,p2)
		{
			draw(linethick,linecolor,p1,p2)
		}
		
		private function draw(linethick,linecolor,p1,p2){
			
			ElementControl.cleanObj(line)
			ElementControl.cleanObj(rot)
				
			this.linecolor=linecolor
			this.linethick=linethick
			line=DrawShape.line(linethick,linecolor,p1,p2)
				
			rot=DrawShape.triangle(linethick,linecolor,new Point(0,0),new Point(-8,-4),new Point(-8,4))
			
			rot.x=p2.x
			rot.y=p2.y	
				
			rot.rotation=Math.atan2(p2.y-p1.y,p2.x-p1.x)/(Math.PI/180)
				
			addChild(line)
			addChild(rot)

		}
		
		
		public function redraw(){

			try{
			
			var mh:Number=Canvas(this.parent.parent).verticalScrollPosition
				
			var mv:Number=Canvas(this.parent.parent).horizontalScrollPosition

			var vx:Number=this.parent.getBounds(this.parent.parent).x+mv
			var vy:Number=this.parent.getBounds(this.parent.parent).y+mh
				
			//trace(vx,vy)
			
			var p1:Point=new Point(-vx+obj1.getBounds(obj1.parent).x+obj1.getBounds(obj1.parent).width/2,-vy+obj1.getBounds(obj1.parent).y)
				
			var p2:Point=new Point(-vx+obj2.getBounds(obj2.parent).x+obj2.getBounds(obj2.parent).width/2,-vy+obj2.getBounds(obj2.parent).y+obj2.getBounds(obj2.parent).height)

			draw(this.linethick,this.linecolor,p1,p2)
			
			}catch(e:Error){
			
				trace(vx,vy)
			
			}
			
		
		}
		
		
	}
}